<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue双向绑定</title>
  <style>
    #container {
      width: 150px;
      height: 400px;
      display: flex;
      flex-direction: column;
      justify-content: space-evenly;
    }

    input {
      /* list-style: none; */
      height: 30px;
    }
  </style>
</head>

<body>
  <div id="container">
    <input type="text" v-model='content'>
    <input type="text" v-model='content'>
    <input type="text" v-model='title'>
    <input type="text" v-model='title'>
    <input type="text" v-model='content'>
    <input type="text" v-model='content'>
  </div>
  <div v-bind='content'> 这里是v-bind=content的div标签</div>
  <div v-bind='title'> 这里是v-bind=title的div标签</div>
  <script>
    function View() {
      let proxy = new Proxy({}, {
        get(obj, property) {
        },
        set(obj, property, value) {
          // 获取所有v-model = property的元素 并遍历，让每一项的值都变成输入的值
          document.querySelectorAll(`[v-model=${property}]`).forEach((v) => {
            v.value = value
          })
          // 获取所有v-bind = property的元素 并遍历，让每一项的innerHTML都变成输入的值
          document.querySelectorAll(`[v-bind=${property}]`).forEach((v) => {
            v.innerHTML = value
          })

        }
      })
      this.init = function () {
        const els = document.querySelectorAll('[v-model]')
        // console.log(els);

        els.forEach(val => {
          val.addEventListener('keyup', function () {
            proxy[this.getAttribute('v-model')] = this.value

          })
        });
      }
    }
    new View().init()
  </script>
</body>


</html>